package poker;

import java.util.Arrays;

abstract class Player 
{
    private static final int HAND_SIZE = 5;
	private String name;
	private Hand hand;
	private int chips = 0;
	private int bid;
	private int wins;
	private boolean allIn;
	
	Player(String name) 
	{
		this.name = name;
		hand = new Hand();
		hand = null;
	}
	void receiveChips(int chips)
	{
		this.chips += chips;
	}
	int playChips(int chips)
	{
		this.chips -= chips;
		return chips;
	}
	void setBid(int bid)
	{
		this.bid = bid;
	}
	void setAllIn(boolean set)
	{
		allIn = set;
	}
	void receiveCards(final Deck deck) 
	{
		if (hand == null) 
		{
			hand = new Hand();
		}
		for (int i = 0; i < HAND_SIZE; i++) 
		{
			hand.cardPick(deck);
		}
	}
	void exchangeCards(final int[] picks, final Deck deck) 
	{
		int len = picks.length;
		Arrays.sort(picks);
		for (int i = len - 1; i >= 0; i--) 
		{
			hand.cardRemove(picks[i]);
		}
		for (int i = 0; i < len; i++) 
		{
			hand.cardPick(deck);
		}
	}	
	int evaluateHand() 
	{
		try 
		{
			return hand.getHandRank();
		} 
		catch (PokerException e) 
		{
			System.out.println(e.getMessage());
			e.printStackTrace();
			return 0;
		}
	}	
	void discardHand() 
	{
		hand = null;
	}
	boolean find(final int query, final int[] array, final int size) 
	{
		boolean result = false;
		for (int i = 0; i < size; i++) 
		{
			if (array[i] == query) 
			{
				result = true;
				break;
			}
		}
		return result;
	}
	void wins()
	{
		wins++;
	}
	boolean isAllIn()
	{
		return allIn;
	}
	int getWins()
	{
		return wins;
	}
	Hand getHand() 
	{
		return hand;
	}
	int getChips()
	{
		return chips;
	}
	int getBid()
	{
		return bid;
	}
	public String toString() 
	{
		if (hand == null) 
		{
			return "This player wasn't dealed";
		} 
		else 
		{
			return hand.toString();
		}
	}
	String getName()
	{
		return name;
	}
	public abstract int[] picks();
	public abstract String buyIn();
	public abstract String action(int currBid, boolean allIn);
	public abstract int bet();
	public abstract int raise();
	
}